package cn.passlink.bletoothchat.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import cn.passlink.bletoothchat.Entity.SendMessage;
import cn.passlink.bletoothchat.R;

public class SendMessageAdapter extends BaseAdapter {
    private Context context;
    private List<SendMessage> messageList;

    public SendMessageAdapter(Context context, List<SendMessage> messageList) {
        this.context = context;
        this.messageList = messageList;
    }

    @Override
    public int getCount() {
        return messageList.size();
    }

    @Override
    public Object getItem(int position) {
        return messageList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.message_box_send_or_rec, parent, false);
            holder = new ViewHolder();
            holder.senderTextView = convertView.findViewById(R.id.right_sender_detials);
            holder.messageTextView = convertView.findViewById(R.id.right_MessageText);
            holder.TimeTextView = convertView.findViewById(R.id.right_send_time);
            holder.LocationTextView=convertView.findViewById(R.id.right_location_detial);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        SendMessage message = messageList.get(position);
        String sender=message.getGrade()+message.getAcademy()+message.getClasses()+":"+message.getSender();
        holder.senderTextView.setText(sender);
        holder.messageTextView.setText(message.getMessage());
        holder.TimeTextView.setText(message.getSend_time());
        holder.LocationTextView.setText(message.getLocation());

        return convertView;
    }

    static class ViewHolder {
        TextView senderTextView;
        TextView messageTextView;
        TextView TimeTextView;
        TextView LocationTextView;
    }
}